package com.collabscm.md.base.dao.impl;

import java.util.List;

import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import com.collabscm.md.base.dao.UserDao;
import com.collabscm.md.base.model.User;
import com.collabscm.pf.CommonConstants;
import com.collabscm.pf.dao.support.DomainDao;

/**
 * 用户DAO
 *
 * @author Zeng Raoxing
 */
@Repository
public class UserDaoImpl extends DomainDao<User, Long> 
						 implements UserDao<User, Long> {
	@Override
	public User getUserByNoAndPW(String accountNo, String password) {
		//Password不能这样
		Query query = entityManager.createNamedQuery(User.FIND_ENABLE_USER_NAME);
		query.setParameter("accountNo", accountNo);
		query.setParameter("password", password);
		//query.setParameter("status", CommonConstants.STATUS_ENABLE);//此处应该用常量
		query.setParameter("status", 2001);
		@SuppressWarnings("unchecked")
		List<User> userList = query.getResultList();//不用分两步写
		logger.info("返回 resultList 大小为 : {}", userList.size());
//		List<User> userList = resultList; 
		if (userList.isEmpty()) {
			logger.debug("根据帐号 [" + accountNo + "], 未找到用户!");
			return null;
		} else if(userList.size() >0){
			logger.warn("");
		}
		return (User)userList.get(0);
	}
}
